#include "b4.h"

int zigzag_order[64] = 
  { 0,   8,  1,  2,  9, 16, 24, 17,
   10,   3,  4, 11, 18, 25, 32, 40,
   33,  26, 19, 12,  5,  6, 13, 20,
   27,  34, 41, 48, 56, 49, 42, 35,
   28,  21, 14,  7, 15, 22, 29, 36,
   43,  50, 57, 58, 51, 44, 37, 30,
   23,  31, 38, 45, 52, 59, 60, 53,
   46,  39, 47, 54, 61, 62, 55, 63 };

void b4_init() {}

void b4_run(fifo<D_QUANT_OUT> *IN, fifo<D_QUANT_OUT> *OUT) {
  D_QUANT_OUT tmp[64];
  int i;
  while (IN->len() >= 64) {
    for (i=0; i<64; ++i) {
      tmp[i] = IN->read(); 
    }    
    for (i=0; i<64; ++i) {
      OUT->write(tmp[zigzag_order[i]]);
    }    
  }
}

